<html>
<head><meta charset="utf-8"><title>I-prioritize #77912 Taking an argument hides lifetime error · t-compiler/wg-prioritization/alerts · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/index.html">t-compiler/wg-prioritization/alerts</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html">I-prioritize #77912 Taking an argument hides lifetime error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213204573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213204573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213204573">(Oct 13 2020 at 19:19)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="3111">@WG-prioritization/alerts</span> issue <a href="https://github.com/rust-lang/rust/issues/77912">#77912</a> has been requested for prioritization.</p>
<h1><a href="https://forge.rust-lang.org/compiler/prioritization/procedure.html#assign-priority-to-unprioritized-issues-with-i-prioritize-label">Procedure</a></h1>
<ul>
<li>Priority?</li>
<li>Regression?</li>
<li>Notify people/groups?</li>
<li>Needs <code>I-nominated</code>?</li>
</ul>



<a name="213206910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213206910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213206910">(Oct 13 2020 at 19:39)</a>:</h4>
<p>Issue <a href="https://github.com/rust-lang/rust/issues/77912">#77912</a>'s prioritization request has been removed.</p>



<a name="213206971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213206971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213206971">(Oct 13 2020 at 19:39)</a>:</h4>
<p>Apparently this is intended behavior :P</p>



<a name="213207161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207161">(Oct 13 2020 at 19:41)</a>:</h4>
<p>yeah, it might make sense to ask in #t-lang if there are any objections to inferring lifetimes to <code>'static</code> if all function inputs do not contain any lifetimes</p>



<a name="213207212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207212">(Oct 13 2020 at 19:41)</a>:</h4>
<p>because at least for me that seems like a fine extension of the current rules (edit: nm I don't think so anymore)</p>



<a name="213207297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207297">(Oct 13 2020 at 19:42)</a>:</h4>
<p>one issue are things like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">test</span><span class="p">(</span><span class="n">v</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">u32</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">&amp;*</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213207333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207333">(Oct 13 2020 at 19:42)</a>:</h4>
<p>Or maybe we could desugar to:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="kt">i32</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>?</p>



<a name="213207343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207343">(Oct 13 2020 at 19:43)</a>:</h4>
<p>personally I'm ok with it, I occasionally run into the opposite issue actually, when I have <code>fn f(&amp;T) -&gt; &amp;U</code> and <code>&amp;U</code> can be <code>*'static</code> but it's infered to the lifetime of <code>&amp;T</code></p>



<a name="213207356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207356">(Oct 13 2020 at 19:43)</a>:</h4>
<p>yeah, that has the same issue for pointers though</p>



<a name="213207441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207441">(Oct 13 2020 at 19:43)</a>:</h4>
<p>Maybe we only desugar if the return value does not use a raw pointer?</p>



<a name="213207449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207449">(Oct 13 2020 at 19:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213207343">said</a>:</p>
<blockquote>
<p>personally I'm ok with it, I occasionally run into the opposite issue actually, when I have <code>fn f(&amp;T) -&gt; &amp;U</code> and <code>&amp;U</code> can be <code>*'static</code> but it's infered to the lifetime of <code>&amp;T</code></p>
</blockquote>
<p>also had that a few times myself, but these cases should always be harmless as <code>'static</code> is always longer than the lt of <code>&amp;T</code></p>



<a name="213207509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207509">(Oct 13 2020 at 19:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213207441">said</a>:</p>
<blockquote>
<p>Maybe we only desugar if the return value does not use a raw pointer?</p>
</blockquote>
<p>no no no no no</p>



<a name="213207510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207510">(Oct 13 2020 at 19:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213207441">said</a>:</p>
<blockquote>
<p>Maybe we only desugar if the return value does not use a raw pointer?</p>
</blockquote>
<p>I feel pretty strongly function types should not depend on the function body</p>



<a name="213207517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207517">(Oct 13 2020 at 19:44)</a>:</h4>
<p>this has caused so much trouble for rustdoc</p>



<a name="213207537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207537">(Oct 13 2020 at 19:44)</a>:</h4>
<p>this is <em>the</em> reason for <a href="https://github.com/rust-lang/rust/issues/75100">https://github.com/rust-lang/rust/issues/75100</a></p>



<a name="213207603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207603">(Oct 13 2020 at 19:45)</a>:</h4>
<p>please don't, as this is relevant for program safety I really feel like we shouldn't use any unintuitive rules here</p>



<a name="213207615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207615">(Oct 13 2020 at 19:45)</a>:</h4>
<p>I guess it just feels confusing to me that the first works and the second does not:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">s</span>: <span class="kp">&amp;</span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213207733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207733">(Oct 13 2020 at 19:46)</a>:</h4>
<p>this would mean that <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/struct.GenericArg.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/struct.GenericArg.html</a> would be a landmine if it didn't contain <code>PhantomData</code></p>



<a name="213207747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207747">(Oct 13 2020 at 19:46)</a>:</h4>
<p>as it uses a <code>NonZeroUsize</code> instead of a pointer</p>



<a name="213207813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207813">(Oct 13 2020 at 19:46)</a>:</h4>
<p>That's beyond my Rust knowledge <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="213207981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207981">(Oct 13 2020 at 19:48)</a>:</h4>
<p>Is there any way to make my example less confusing? If <code>foo</code> used <code>s</code> in the return value, it would make sense, but having the addition of an unused argument change whether the code compiles is just confusing to me.</p>



<a name="213207996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213207996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213207996">(Oct 13 2020 at 19:48)</a>:</h4>
<p>Could someone move this to <a class="stream" data-stream-id="213817" href="/#narrow/stream/213817-t-lang">#t-lang</a>?</p>



<a name="213208008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208008">(Oct 13 2020 at 19:48)</a>:</h4>
<p>it's lifetime elision</p>



<a name="213208021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208021">(Oct 13 2020 at 19:48)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nomicon/lifetime-elision.html">https://doc.rust-lang.org/nomicon/lifetime-elision.html</a></p>



<a name="213208071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208071">(Oct 13 2020 at 19:48)</a>:</h4>
<p>I know, it's just confusing to me that it's applied in one case but not another.</p>



<a name="213208164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208164">(Oct 13 2020 at 19:49)</a>:</h4>
<p>Likewise, that A works, but B does not:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">s</span>: <span class="kp">&amp;</span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">// A</span>
<span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">s</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">// B</span>
</code></pre></div>



<a name="213208218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208218">(Oct 13 2020 at 19:50)</a>:</h4>
<p>I do agree that this can be confusing</p>



<a name="213208222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208222">(Oct 13 2020 at 19:50)</a>:</h4>
<p>I guess it makes sense from the viewpoint of the compiler, but as a user it is very unintuitive</p>



<a name="213208251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208251">(Oct 13 2020 at 19:50)</a>:</h4>
<p>well it's meant to make writing functions easier</p>



<a name="213208278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208278">(Oct 13 2020 at 19:50)</a>:</h4>
<p>imagine if you hade to write <code>fn f&lt;'a&gt;(&amp;'a str) -&gt; &amp;'a str{</code> everywhere</p>



<a name="213208297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208297">(Oct 13 2020 at 19:50)</a>:</h4>
<p>instead of <code>fn f(&amp;str) -&gt; &amp;str</code></p>



<a name="213208334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208334">(Oct 13 2020 at 19:51)</a>:</h4>
<p>I <em>like</em> it, I just want it to be more general</p>



<a name="213208360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208360">(Oct 13 2020 at 19:51)</a>:</h4>
<p>the rule is pretty much: "assign each elided lt in the function args a unique lt param, if there is exactly one elided lifetime there use that one for the return argument"</p>



<a name="213208502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208502">(Oct 13 2020 at 19:52)</a>:</h4>
<p>Is that rule in the docs?</p>



<a name="213208524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208524">(Oct 13 2020 at 19:52)</a>:</h4>
<p>It's helpful :)</p>



<a name="213208545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208545">(Oct 13 2020 at 19:53)</a>:</h4>
<p>it's here <a href="https://doc.rust-lang.org/nomicon/lifetime-elision.html#lifetime-elision">https://doc.rust-lang.org/nomicon/lifetime-elision.html#lifetime-elision</a></p>



<a name="213208562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208562">(Oct 13 2020 at 19:53)</a>:</h4>
<p>it might make sense to move this to the actual rust book</p>



<a name="213208612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208612">(Oct 13 2020 at 19:53)</a>:</h4>
<p>A lot of stuff in the nomicon seems like it belongs in the book :)</p>



<a name="213208677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208677">(Oct 13 2020 at 19:54)</a>:</h4>
<p>but as the only error case here is: user gets a fairly helpful compiler error to manually add lt params and now uses more than necessary</p>



<a name="213208687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208687">(Oct 13 2020 at 19:54)</a>:</h4>
<p>i don't think that it's worth it</p>



<a name="213208761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208761">(Oct 13 2020 at 19:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213208612">said</a>:</p>
<blockquote>
<p>A lot of stuff in the nomicon seems like it belongs in the book :)</p>
</blockquote>
<p>the more info you put into a summary the less of a summary it is</p>



<a name="213208883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208883">(Oct 13 2020 at 19:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213207297">said</a>:</p>
<blockquote>
<p>one issue are things like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">test</span><span class="p">(</span><span class="n">v</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">u32</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">&amp;*</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

</blockquote>
<p>I don't quite understand your concern. What stops someone from doing this?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">test</span><span class="p">(</span><span class="n">s</span>: <span class="kp">&amp;</span><span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">v</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">u32</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">&amp;*</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213208899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208899">(Oct 13 2020 at 19:56)</a>:</h4>
<p>It compiles fine, and has the exact same issue</p>



<a name="213208912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208912">(Oct 13 2020 at 19:56)</a>:</h4>
<p>considering that the goal of the introductory material is to get people to start using rust I personally prefer to remove everything that is not strictly necessary or explained by compiler errors</p>



<a name="213208946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213208946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213208946">(Oct 13 2020 at 19:56)</a>:</h4>
<blockquote>
<p>What stops someone from doing this?</p>
</blockquote>
<p>that people write code like this less often</p>



<a name="213209041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209041">(Oct 13 2020 at 19:57)</a>:</h4>
<p>we may want to lint this case</p>



<a name="213209073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209073">(Oct 13 2020 at 19:58)</a>:</h4>
<p>By the way, what is the underlying issue with eliding lifetimes for this?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">test</span><span class="p">(</span><span class="n">v</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">u32</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">&amp;*</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213209105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209105">(Oct 13 2020 at 19:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213209041">said</a>:</p>
<blockquote>
<p>we may want to lint this case</p>
</blockquote>
<p>The more the merrier! :)</p>



<a name="213209137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209137">(Oct 13 2020 at 19:58)</a>:</h4>
<p>yeah <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> do you want to open an issue for this in the rust repo?</p>



<a name="213209189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209189">(Oct 13 2020 at 19:59)</a>:</h4>
<p>Sure, feel free to edit the issue if I get anything wrong :)</p>



<a name="213209264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209264">(Oct 13 2020 at 19:59)</a>:</h4>
<blockquote>
<p>By the way, what is the underlying issue with eliding lifetimes for this?</p>
</blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">z</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">test</span><span class="p">(</span><span class="n">y</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213209368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209368">(Oct 13 2020 at 20:00)</a>:</h4>
<p>(<code>test</code> has to unsafe anyways, as we could always call it with <code>0 as *const u32</code> but that's beside the point rn)</p>



<a name="213209518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209518">(Oct 13 2020 at 20:01)</a>:</h4>
<p>When casting pointers to references you have to be very careful with the lifetime of this reference to prevent use after frees</p>



<a name="213209703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213209703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213209703">(Oct 13 2020 at 20:02)</a>:</h4>
<p>very often it is instead helpful to "remember" the correct lifetime of pointers by using a newtype with <code>PhantomData</code></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">WeirdPtr</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">ptr</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">_marker</span>: <span class="nc">PhantomData</span><span class="o">&lt;&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213210310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210310">(Oct 13 2020 at 20:08)</a>:</h4>
<p>Opened <a href="https://github.com/rust-lang/rust/issues/77914">#77914</a></p>



<a name="213210406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210406">(Oct 13 2020 at 20:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213209703">said</a>:</p>
<blockquote>
<p>very often it is instead helpful to "remember" the correct lifetime of pointers by using a newtype with <code>PhantomData</code></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">WeirdPtr</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">ptr</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">_marker</span>: <span class="nc">PhantomData</span><span class="o">&lt;&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

</blockquote>
<p>Huh, interesting. I've never quite understood <code>PhantomData</code>. I think I'll go and read up on it so I finally understand it :)</p>



<a name="213210437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210437">(Oct 13 2020 at 20:09)</a>:</h4>
<p>Why would you use this special wrapper instead of just using <code>&amp;'a T</code>?</p>



<a name="213210463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210463">(Oct 13 2020 at 20:09)</a>:</h4>
<p>&amp;T must always be valid for reads</p>



<a name="213210515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210515">(Oct 13 2020 at 20:10)</a>:</h4>
<p>*const T can be invalid as long as you don't dereference it</p>



<a name="213210539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210539">(Oct 13 2020 at 20:10)</a>:</h4>
<p>But why would you want to pass around an invalid ptr?</p>



<a name="213210567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210567">(Oct 13 2020 at 20:10)</a>:</h4>
<p>I guess I need to do more low-level Rust stuff :)</p>



<a name="213210638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210638">(Oct 13 2020 at 20:11)</a>:</h4>
<p>you can also use this to store some data in the lower bits of the pointer in case the pointee has an alignment greater than 1</p>



<a name="213210670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210670">(Oct 13 2020 at 20:11)</a>:</h4>
<p>this is what <code>GenericArg</code> does</p>



<a name="213210676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210676">(Oct 13 2020 at 20:11)</a>:</h4>
<p><a href="https://anniecherkaev.com/the-secret-life-of-nan">https://anniecherkaev.com/the-secret-life-of-nan</a></p>



<a name="213210700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210700">(Oct 13 2020 at 20:11)</a>:</h4>
<p>Wow, way over my head <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="213210757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210757">(Oct 13 2020 at 20:12)</a>:</h4>
<p>Oh, I think I've read about that before</p>



<a name="213210878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210878">(Oct 13 2020 at 20:13)</a>:</h4>
<p>So this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">WeirdPtr</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">ptr</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">_marker</span>: <span class="nc">PhantomData</span><span class="o">&lt;&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>is an optimization to store a reference <em>and</em> some data?</p>



<a name="213210896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210896">(Oct 13 2020 at 20:13)</a>:</h4>
<p>it could be</p>



<a name="213210911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210911">(Oct 13 2020 at 20:13)</a>:</h4>
<p>it's a pointer that does not have a <code>restrict dereferencable inbounds</code> LLVM attribute</p>



<a name="213210922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210922">(Oct 13 2020 at 20:13)</a>:</h4>
<p>it could also be a shared reference which might get written to somewhere else</p>



<a name="213210938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213210938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213210938">(Oct 13 2020 at 20:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213210922">said</a>:</p>
<blockquote>
<p>it could also be a shared reference which might get written to somewhere else</p>
</blockquote>
<p>What do you mean?</p>



<a name="213211021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211021">(Oct 13 2020 at 20:14)</a>:</h4>
<p><code>*const u32</code> does not have any aliasing restrictions</p>



<a name="213211068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211068">(Oct 13 2020 at 20:14)</a>:</h4>
<p>so you can mutate the value pointed to by a <code>*const u32</code> without causing undefined behavior</p>



<a name="213211087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211087">(Oct 13 2020 at 20:15)</a>:</h4>
<p>well</p>



<a name="213211093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211093">(Oct 13 2020 at 20:15)</a>:</h4>
<p>I think you mean <code>*mut T</code>?</p>



<a name="213211097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211097">(Oct 13 2020 at 20:15)</a>:</h4>
<p>both</p>



<a name="213211103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211103">(Oct 13 2020 at 20:15)</a>:</h4>
<p>Huh, so is the <code>const</code> part just a note saying "this shouldn't be mutated, but can be"?</p>



<a name="213211126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211126">(Oct 13 2020 at 20:15)</a>:</h4>
<p>there is close to no difference between <code>*const T</code> and <code>*mut T</code> except for variance</p>



<a name="213211143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211143">(Oct 13 2020 at 20:15)</a>:</h4>
<p>A new term to look up <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="213211187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211187">(Oct 13 2020 at 20:16)</a>:</h4>
<p>yeah, <code>*const T</code> is pretty much only right if the pointee is only meant to be read</p>



<a name="213211198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211198">(Oct 13 2020 at 20:16)</a>:</h4>
<p>It's historically there for documentation purposes mainly, in practice it's for variance too</p>



<a name="213211211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211211">(Oct 13 2020 at 20:16)</a>:</h4>
<p>at least in my experience it is mostly for variance</p>



<a name="213211215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211215">(Oct 13 2020 at 20:16)</a>:</h4>
<p><code>*const T</code> is valid for an owning pointer too</p>



<a name="213211245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211245">(Oct 13 2020 at 20:17)</a>:</h4>
<p>it is so easy to shoot yourself in the foot when having a covariant mutable pointer</p>



<a name="213211254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211254">(Oct 13 2020 at 20:17)</a>:</h4>
<p>So you mean that <code>*const T</code> and <code>*mut T</code> are the same except that <code>*mut T</code> can be passed to a function expecting <code>*const T</code> but not vice versa?</p>



<a name="213211320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211320">(Oct 13 2020 at 20:18)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> I mean that the usage in C code (where the terminology comes from) was for docs (memcpy, etc.)<br>
Nowadays, in Rust, the usage is for variance indeed</p>



<a name="213211399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211399">(Oct 13 2020 at 20:18)</a>:</h4>
<p>no, you can go from <code>*const &amp;'static T</code> to <code>*const &amp;'a T</code> but not from a <code>*mut &amp;'static T</code> to <code>*mut &amp;'a T</code></p>



<a name="213211649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211649">(Oct 13 2020 at 20:21)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> variance is the mechanic that allows to "shrink lifetimes" inside a type that would be generic over some lifetime parameter. Which seems like a harmless thing to do, but it isn't always the case: it is unsound to overwrite a long-lived borrow with a short-lived one. Since <code>*mut</code> hints at being used for mutation, it is invariant / it doesn't allow lifetimes to shrink, whereas <code>*const</code> allows it</p>



<a name="213211701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211701">(Oct 13 2020 at 20:21)</a>:</h4>
<p>For more info, see the nomicon chapter about it, or search in <a href="http://users.rust-lang.org">users.rust-lang.org</a> for some detailed posts about the topic</p>



<a name="213211975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213211975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213211975">(Oct 13 2020 at 20:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213211399">said</a>:</p>
<blockquote>
<p>no, you can go from <code>*const &amp;'static T</code> to <code>*const &amp;'a T</code> but not from a <code>*mut &amp;'static T</code> to <code>*mut &amp;'a T</code></p>
</blockquote>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6dfe4589c901ce2457553d3cd4e97117">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6dfe4589c901ce2457553d3cd4e97117</a></p>



<a name="213212144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213212144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213212144">(Oct 13 2020 at 20:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213211649">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> variance is the mechanic that allows to "shrink lifetimes" inside a type that would be generic over some lifetime parameter. Which seems like a harmless thing to do, but it isn't always the case: it is unsound to overwrite a long-lived borrow with a short-lived one. Since <code>*mut</code> hints at being used for mutation, it is invariant / it doesn't allow lifetimes to shrink, whereas <code>*const</code> allows it</p>
</blockquote>
<p>That clears it up, thanks :)</p>



<a name="213212278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213212278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213212278">(Oct 13 2020 at 20:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/245100-t-compiler.2Fwg-prioritization.2Falerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error/near/213211254">said</a>:</p>
<blockquote>
<p>So you mean that <code>*const T</code> and <code>*mut T</code> are the same except that <code>*mut T</code> can be passed to a function expecting <code>*const T</code> but not vice versa?</p>
</blockquote>
<p>oh, that's actually news for me <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> <code>*mut T</code> does decay to <code>*const T</code>. Thanks <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="213225656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize%20%2377912%20Taking%20an%20argument%20hides%20lifetime%20error/near/213225656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/245100-t-compiler/wg-prioritization/alerts/topic/I-prioritize.20.2377912.20Taking.20an.20argument.20hides.20lifetime.20error.html#213225656">(Oct 13 2020 at 22:36)</a>:</h4>
<p>I had no idea, I was just guessing <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>